﻿using System;
using System.Collections.Generic;
using System.Text;
using Peekaboo2008.model;
using System.Data;
using System.Data.SqlClient;
using Peekaboo2008.util;


namespace Peekaboo2008.dao
{
    class ChiTietNhapXuatDAO
    {
        /*
         * Duoc su dung trong PhieuNhapXuatDAO de dong bo hoa du lieu
         * */
        public static String Insert(ChiTietNhapXuatModel _model)
        {
            String returnID = "";
            int i = 0;
            SqlParameter[] param = new SqlParameter[16];
            param[i] = new SqlParameter("Ma_phieu_xuat_nhap", SqlDbType.Int);
            param[i++].Value = _model.MaPhieuNhapXuat;
            param[i] = new SqlParameter("Ma_hang_hoa", SqlDbType.Int);
            param[i++].Value = _model.MaHangHoa;
            param[i] = new SqlParameter("Ghi_chu", SqlDbType.NVarChar);
            param[i++].Value = _model.GhiChu;
            param[i] = new SqlParameter("So_luong", SqlDbType.Float);
            param[i++].Value = _model.SoLuong;
            param[i] = new SqlParameter("Gia_ban", SqlDbType.Float);
            param[i++].Value = _model.GiaBan;
            param[i] = new SqlParameter("Thanh_tien", SqlDbType.Float);
            param[i++].Value = _model.ThanhTien;
            param[i] = new SqlParameter("Thue", SqlDbType.Float);
            param[i++].Value = _model.Thue;
            param[i] = new SqlParameter("Tien_thue", SqlDbType.Float);
            param[i++].Value = _model.TienThue;
            param[i] = new SqlParameter("Tong_tien", SqlDbType.Float);
            param[i++].Value = _model.TongTien;
            param[i] = new SqlParameter("Chiet_khau", SqlDbType.Float);
            param[i++].Value = _model.ChietKhau;
            param[i] = new SqlParameter("Tien_chiet_khau", SqlDbType.Float);
            param[i++].Value = _model.TienChietKhau;
            param[i] = new SqlParameter("Han_su_dung", SqlDbType.VarChar);
            param[i++].Value = _model.HanSuDung;
            param[i] = new SqlParameter("Bao_hanh", SqlDbType.VarChar);
            param[i++].Value = _model.BaoHanh;
            param[i] = new SqlParameter("Phi_van_chuyen", SqlDbType.Float);
            param[i++].Value = _model.PhiVanChuyen;
            param[i] = new SqlParameter("So_luong_goc", SqlDbType.Float);
            param[i++].Value = _model.SoLuongGoc;
            param[i] = new SqlParameter("OutID", SqlDbType.Int);
            param[i].Direction = ParameterDirection.Output;

            DataUtil.executeNonStore("sp_ChiTietNhapXuat_Insert", param);

            returnID = param[i].Value.ToString();
            return returnID;
        }

        public static void deleteById(String id)
        {
            int i = 0;
            SqlParameter[] param = new SqlParameter[1];
            param[i] = new SqlParameter("ID", SqlDbType.Int);
            param[i++].Value = id;

            DataUtil.executeNonStore("sp_ChiTietNhapXuat_DeleteById", param);
        }

        public static void deleteByMaPhieuNhapXuat(String MaPhieuNhapXuat)
        {
            int i = 0;
            SqlParameter[] param = new SqlParameter[1];
            param[i] = new SqlParameter("Ma_phieu_nhap_xuat", SqlDbType.Int);
            param[i++].Value = MaPhieuNhapXuat;

            DataUtil.executeNonStore("sp_ChiTietNhapXuat_DeleteByMaPhieuNhapXuat", param);
        }
        public static DataTable getByMaPhieuNhapXuat(String MaPhieuNhapXuat)
        {
            int i = 0;
            SqlParameter[] param = new SqlParameter[1];
            param[i] = new SqlParameter("MaPhieuNhapXuat", SqlDbType.Int);
            param[i++].Value = MaPhieuNhapXuat;

            return DataUtil.executeStore("sp_ChiTietNhapXuat_GetByMaPhieuNhapXuat", param);
        }
    }
}
